<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Yy</title>
</head>

<body>
    <button class="get">查询数据</button>
    <button class="post">添加数据</button>
    <button class="put">修改数据</button>
    <button class="delete">删除数据</button>
    <script src="/axios.min.js"></script>
    <script src="/jquery.js"></script>
    <script>
        document.querySelector(".get").onclick = function() {
            axios.get("/fruits").then(res => {
                console.log(res.data)
            })
        }

        // document.querySelector(".post").onclick = function() {
        //     axios.post("/fruits", {
        //         fruit: "草莓"
        //     }).then(res => {
        //         console.log(res.data)
        //     })
        // }
        // document.querySelector(".put").onclick = function() {
        //     axios.put("/fruits/0", {
        //         fruit: "西瓜"
        //     }).then(res => {
        //         console.log(res.data)
        //     })
        // }
        // document.querySelector(".delete").onclick = function() {
        //         axios.delete("/fruits/0").then(res => {
        //             console.log(res.data)
        //         })
        //     }
        $(".get").click(function() {
            $.ajax({
                url: "/fruits",
                type: "get"
            }).done(res => {
                console.log(res, "jquery的ajax get方法")
            })
        })
        $(".post").click(function() {
            $.ajax({
                url: "/fruits",
                type: "post",
                data: {
                    fruit: "草莓"
                }
            }).done(res => {
                console.log(res, "jquery的ajax post方法")
            })
        })

        $(".put").click(function() {
            $.ajax({
                url: "/fruits/0",
                type: "put",
                data: {
                    fruit: "西瓜"
                }
            }).done(res => {
                console.log(res, "jquery的ajax put方法")
            })
        })
        $(".delete").click(function() {
            $.ajax({
                url: "/fruits/0",
                type: "delete",
            }).done(res => {
                console.log(res, "jquery的ajax delete")
            })
        })
    </script>
</body>

</html>